<template>
  <div class="unfinish">
    <van-nav-bar @click-left='goBack()' left-arrow="" title="未完成维修设备">
    </van-nav-bar>
    <div class="area">
      <van-search v-model="searchData" placeholder="搜索关键字" @focus='showkeywords=true'></van-search>
      <div class="keywords" v-if="showkeywords">
        <van-button type="default" @click='searchRepair("1")'>设备名称</van-button>
        <van-button type="default" @click='searchRepair("2")'>维修单号</van-button>
      </div>
      <repair :status='true' :allInfo='allInfo' :isSearch='isSearch'></repair>
    </div>
  </div>
</template>

<script>
  import {Toast} from 'vant'
  import repair from '../subcom/repair.vue'
  export default {
    data() {
      return {
        showkeywords: false,
        searchData: '',
        allInfo:[],
        isSearch:false
      }
    },
    watch:{
      searchData(newval){
        if(!this.searchData){
          this.isSearch = false
        }
      },
      isSearch(newval){
        this.$forceUpdate()
      }
    },
    methods: {
      searchRepair(type) {
        this.allInfo = []
        this.isSearch = true
        //查找的设备id
        let fid = ''
        //查找的维修单号
        let rid = ''
        this.showkeywords = false
        if (type === '1') {
          fid = this.searchData
        } else if (type === '2') {
          rid = this.searchData
        }
        this.$axios.post('/Maintenance/selectMaintenance.do', {
          facilityName: fid,
          id: rid,
          starttime: '',
          endtime: ''
        }).then(res => {
          if (res.data.status === 200) {
            let newData = res.data.msg
            console.log(newData)
            newData.map((value, index) => {
              if (value.state === 2) {

                this.allInfo.push(value)
              }
            })
            console.log(this.allInfo)
            if (this.allInfo.length === 0) {
              Toast.fail({
                message: '暂无数据',
                duration: 900
              })
            }
          }

        })
      },
    },
    components: {
      repair
    }
  }
</script>

<style scoped="scoped">
  van-button {
    color: #999;
  }

  .van-button--default {
    border: none;
    color: white;
    background: lightblue;
    margin-left: .5rem;
    height: 2rem;
    line-height: 2rem;
  }

  .keywords {
    font-size: .8rem;
    margin-bottom: .8rem;
  }
</style>
